<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
    <title>芳小微宣</title>
    <link rel="stylesheet" href="css/index.css">
    <script src="js/jquery.min.js"> </script>
    <script src="js/jquery.cookie.js"> </script>
    <script src="js/index.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;
            background: url("images/loginBg.png");
            background-size: 100% 100%;
            width: 100%;
            height: 100%;
            background-repeat: no-repeat;
            padding-bottom: 0;
            position: absolute;
        }
    </style>

</head>
<body>
<div style="text-align: center"><img src="images/logo.png" style="width:60%; margin-top: 22%;"></div>
<div style="text-align: center;margin-top: 25%;font-size: 4.62rem">
    <span id="errorInfo" style="color: red;position:absolute; top: 47.4%;left: 36%;"></span>
    <img src="images/box.png" style="width: 72%">
    <span class="inputWord" style=" ">登录</span>
    <input type="text" class="inputSty" id="username"/>
</div>
<div style="text-align: center;margin-top: 5%;font-size: 4.62rem"><img src="images/box.png" style="width: 72%">
    <span class="inputWord" style="">密码</span>
    <input type="password" class="inputSty" style="" id="password"/>
</div>
<div style="text-align: center;margin-top: 5%;"><img src="images/login.png" style="width: 72%" id="login" class="login">
    <span style=" position: absolute; left: 39%;margin-top: 1.3rem;color: #fff;font-size: 5.72rem"  class="login">立即登录</span>
</div>

<script>

    var token;
   $("input").focus(function(){
       $("body").height($("body").height());
       $("body").css("background","100% 100%");
   });
    $(".login").click(function(){
        var username = $("#username").val();
        var password = $("#password").val();
        if(username.replace(/[ ]/g, "") == ""){
           $("#errorInfo").html("请输入用户名!")
        }else if(password.replace(/[ ]/g, "") == ""){
            $("#errorInfo").html("请输入密码!")
        }else{
            $.ajax({
                type : "POST",
                url : path + "/api/weixin/login",
                data : {
                    "username" :username,
                    "password" :password,
                    "token" : token ? "":token
                },
                dataType : 'json',
                success : function(msg) {
                    if(msg.code == 0){
                       token = msg.token ;
                        window.localStorage.setItem('token',token);
                        window.localStorage.setItem('username',username);
                        window.location.href = "index.html";
                    }else if(msg.code == 500){
                        $("#errorInfo").html(msg.msg)
                    }
                }
            })
        }
    })


</script>
</body>
</html>